package com.lancoo.answer.view.base


import androidx.viewbinding.ViewBinding
import androidx.recyclerview.widget.RecyclerView
import android.view.ViewGroup

abstract class XBaseRecyclerAdapter<VB : ViewBinding> : RecyclerView.Adapter<XBaseRecyclerHolder<*>>() {

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): XBaseRecyclerHolder<VB> {
        return XBaseRecyclerHolder(onBindingView(viewGroup))
    }

    override fun onBindViewHolder(holder: XBaseRecyclerHolder<*>, position: Int) {
        onBindingData(holder as XBaseRecyclerHolder<VB>, position)
    }


    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    protected abstract fun onBindingView(viewGroup: ViewGroup?): VB

    protected abstract fun onBindingData(holder: XBaseRecyclerHolder<VB>, position: Int)

}